<?php if ( ! defined('WDK_PATH')) exit('No direct script access allowed');
require_once BASE_PATH.'app/controller.php';
class Main extends Controller
{
	private $pm;
	function __construct()
	{
		parent::__construct();
		$this->_init();
	}
	
	protected function _init() 
	{	
		$this->pm = Wdk::get('PostManager');
		$this->pm['page'] = 1;
		$this->pm['order'] = array("bbs_post_insert_time DESC");
	}
	
	public function index()
	{
		/*****************************************************************************************************************************
		 * BASIC VARS
		*****************************************************************************************************************************/
		$assign_data = array();
		/****************************************************************************************************************************/
		try 
		{
			$assign_data['notice'] = $this->format($this->pm->getLatest('notice', 5));
			$assign_data['free'] = $this->format($this->pm->getLatest('free', 10));
			$assign_data['phone_adv'] = $this->format($this->pm->getLatest('phone_adv', 10));
			
			$ua = Wdk::get('UserAttendManager');
			$assign_data['userattend'] = $ua->getLatest(5);
		}
		catch(WException $e)
		{
			parent::_error($e);
		}
		/*****************************************************************************************************************************
		 * RESULT
		*****************************************************************************************************************************/	
		parent::_view($assign_data);
		/****************************************************************************************************************************/
	}
	
	public function parking()
	{
		/*****************************************************************************************************************************
		 * RESULT
		*****************************************************************************************************************************/
		parent::_layout('blank');
		parent::_view(array(), 'app/main/parking.html');
		exit;
		/****************************************************************************************************************************/
	}
	
	private function format($list=array())
	{
		if(empty($list) == false)
		{
			foreach($list as $i=>$data)
			{
				$data->setTitleLength(38);
			}	
		}
		return $list;
	}
}